using System;
using System.Collections.Generic;
using System.Text;
using Entity;

namespace eShop.Business
{
    public class Inquires
    {
        #region Inquires Private Fields

        int _inquiryId;
        string _name = string.Empty;
        string _organization = string.Empty;
        string _telephone = string.Empty;
        string _emailAddress = string.Empty;
        string _website = string.Empty;
        string _subject = string.Empty;
        string _inquires = string.Empty;
        DateTime _createDate;
        bool _isContacted;

        #endregion

        #region Inquires Constractor
        public Inquires() { }

        public Inquires
        (
            int inquiryId,
            string name,
            string organization,
            string telephone,
            string emailAddress,
            string website,
            string subject,
            string inquires,
            DateTime createDate,
            bool isContacted
        )
        {
            this._inquiryId = inquiryId;
            this._name = name;
            this._organization = organization;
            this._telephone = telephone;
            this._emailAddress = emailAddress;
            this._website = website;
            this._subject = subject;
            this._inquires = inquires;
            this._createDate = createDate;
            this._isContacted = isContacted;
        }

        #endregion

        #region Public Properties


        public int InquiryId
        {
            get { return _inquiryId; }
        }


        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public string Organization
        {
            get { return _organization; }
            set { _organization = value; }
        }

        public string Telephone
        {
            get { return _telephone; }
            set { _telephone = value; }
        }

        public string EmailAddress
        {
            get { return _emailAddress; }
            set { _emailAddress = value; }
        }

        public string Website
        {
            get { return _website; }
            set { _website = value; }
        }

        public string Subject
        {
            get { return _subject; }
            set { _subject = value; }
        }

        public string Inquiry
        {
            get { return _inquires; }
            set { _inquires = value; }
        }

        public DateTime CreateDate
        {
            get { return _createDate; }
            set { _createDate = value; }
        }

        public bool IsContacted
        {
            get { return _isContacted; }
            set { _isContacted = value; }
        }



        #endregion

        public void Create()
        {

            try
            {
                this._inquiryId = TblInquires.CreateNewTblInquires(Name, Organization, Telephone, EmailAddress, Website, Subject, Inquiry, CreateDate, IsContacted);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        
        private static List<Inquires> LoadFromList(List<TblInquires> tblInquires)
        {
            List<Inquires> result = new List<Inquires>();
            for (int i = 0; i < tblInquires.Count; i++)
            {
                TblInquires tmpTblInquires = tblInquires[i];
                result.Add(new Inquires(tmpTblInquires.InquiryId, tmpTblInquires.Name, tmpTblInquires.Organization, tmpTblInquires.Telephone, tmpTblInquires.EmailAddress, tmpTblInquires.Website, tmpTblInquires.Subject, tmpTblInquires.Inquires, tmpTblInquires.CreateDate, tmpTblInquires.IsContacted));
            }
            return result;
        }

        public static List<Inquires> GetInquires(string orderBy, int firstItemPosition, int maxItem)
        {
            List<TblInquires> _Inquires = TblInquires.GetAllTblInquiresPaged(orderBy, firstItemPosition, maxItem);
            return LoadFromList(_Inquires);
        }

        public static int TotalInquires()
        {
            int count = 0;
            count = TblInquires.GetAllTblInquiresPagedCount("", 0, 100);
            return count;
        }



    }
}
